package com.lyj.sc.dynamicProgramming.test320220718;

/**
 * @program: code-random
 * @description: 一和零
 * @author: lyj
 * @create: 2022-07-18 11:18
 * @version: 1.0
 * @Modifier By:
 **/
public class yihelin {
    public int findMaxForm(String[] strs, int m, int n) {
        //1.定义dp数组 两个维度的背包数组
        int [][] dp = new int[m+1][n+1];
        for(String s : strs){
            //得到遍历数
            int zeronum = 0;
            int onenum = 0;
            for (char c : s.toCharArray()){
                //得到遍历树
                if(c=='1'){
                    onenum++;
                }else {
                    zeronum++;
                }
            }
            //3.遍历循环  先遍历背包
            for (int i = m; i >= zeronum; i--) {
                for (int j = n; j >= onenum; j--) {
                    //4.递推公司
                    dp[i][j]=Math.max(dp[i][j],dp[i-zeronum][j-onenum]+1);
                }
            }
        }
        return dp[m][n];
    }
}
